module nade.array;


T head(T)(T[] arr)
{
	return arr[0];
}

T[] tail(T)(T[] arr)
{
	return arr[1 .. $];
}

T take(T)(ref T[] arr)
{
	auto r = arr.head();
	arr = arr.tail();
	return r;
}


T remove(T)(ref T arr, uint i)
{
	arr = arr[0 .. i] ~ arr[(i + 1) .. $];
	return arr;
}

int find(T)(in T[] arr, T element)
{
	foreach(k, T e; arr)
		if(e == element)
			return k;

	return -1;
}

void remove(T)(ref T[] arr, T element)
{
	foreach(k, T e; arr)
	{
		if(e == element)
		{
			arr.remove(k);
			break;
		}
	}
}

TV[TK] dup(TK, TV)(TV[TK] arr) {
	TV[TK] result;
	foreach(k, v;  arr) result[k] = v;
	return result;
}
